{extend name="layout/base" /}
<!-- 标题 -->
{block name="title"}管理首页{/block}
<!-- CSS -->
{block name="css"}{/block}
<!-- 具体内容 -->
{block name="content"}
<h2 class="header-dividing">网站设置 <small>Website setting</small></h2>
<div class="mb10">
    <ul class="nav nav-primary">
        <li class="active"><a data-tab href="#Content1">网站设置</a></li>
        {notempty name="param"}
        <li><a data-tab href="#Content2">其它设置</a></li>
        {/notempty}
    </ul>
</div>
<form class="form-horizontal" id="form-page-submit" method="post" action="{:url('@admin/website/save')}">
<input type="hidden" name="site_id" value="{$siteid}">
<div class="panel tab-content">
    <div class="tab-pane active" id="Content1">
        <div class="panel-heading p0"><h4 class="hl-default p15 mt0">网站设置</h4></div>
        <div class="panel-body">
            <div class="form-group">
                <label class="col-lg-1 col-md-2 col-sm-2" for="site_home">首页标题</label>
                <div class="col-sm-6"><input type="text" class="form-control" id="site_home" name="site_home" placeholder="首页标题" value="{$site['site_home']}"></div>
                <div class="col-sm-3 help-block with-errors">网站首页 (关键词/主营业务)</div>
                <div class="col-sm-2 help-block"><code contenteditable="true">$site_home</code></div>
            </div>
            <div class="form-group">
                <label class="col-lg-1 col-md-2 col-sm-2 required" for="site_title">网站名称</label>
                <div class="col-sm-6"><input type="text" class="form-control" id="site_title" name="site_title" placeholder="网站名称" value="{$site['site_title']}" required></div>
                <div class="col-sm-3 help-block with-errors">网站名称 (公司名称)</div>
                <div class="col-sm-2 help-block"><code contenteditable="true">$site_title</code></div>
            </div>
            <div class="form-group">
                <label class="col-lg-1 col-md-2 col-sm-2" for="site_keywords">关键词</label>
                <div class="col-sm-6"><input type="text" class="form-control" id="site_keywords" name="site_keywords" placeholder="网站关键词" value="{$site['site_keywords']}"></div>
                <div class="col-sm-3 help-block with-errors">keywords (SEO优化)</div>
                <div class="col-sm-2 help-block"><code contenteditable="true">$site_keywords</code></div>
            </div>
            <div class="form-group">
                <label class="col-lg-1 col-md-2 col-sm-2" for="site_description">网站描述</label>
                <div class="col-sm-6"><textarea class="form-control" placeholder="网站描述" name="site_description" id="site_description" rows="5">{$site['site_description']}</textarea></div>
                <div class="col-sm-3 help-block with-errors">codedescription (SEO优化)</div>
                <div class="col-sm-2 help-block"><code contenteditable="true">$site_description</code></div>
            </div>
            <div class="form-group">
                <label class="col-lg-1 col-md-2 col-sm-2" for="site_jscode">JS代码</label>
                <div class="col-sm-6"><textarea class="form-control" placeholder="网站描述" name="site_jscode" id="site_jscode" rows="5">{$site['site_jscode']}</textarea></div>
                <div class="col-sm-3 help-block with-errors">流量统计代码</div>
                <div class="col-sm-2 help-block"><code contenteditable="true">$site_jscode</code></div>
            </div>
        </div>
    </div>
    {notempty name="param"}
    <div class="tab-pane" id="Content2">
        <div class="panel-heading p0"><h4 class="hl-default p15 mt0">其它设置</h4></div>
        <div class="panel-body">
            {volist name="param" id="vo"}
            <div class="form-group">
                <label class="col-lg-1 col-md-2 col-sm-2 {$vo['param_required'] != '1' ?: 'required'}" for="param_{$vo['param_id']}">{$vo['param_name']}</label>
                <div class="col-sm-6">{:make_input($vo)}</div>
                <div class="col-sm-3 help-block with-errors">&nbsp;{$vo['param_tips']}</div>
                <div class="col-sm-2 help-block"><code contenteditable="true">$site_param_{$vo['param_id']}</code></div>
            </div>
            {/volist}
        </div>
    </div>
    {/notempty}
    <div class="panel-footer text-center">
        <button type="submit" class="btn btn-primary btn-submit">保存信息</button>
    </div>
</div>
</form>
{/block}

<!-- JS -->
{block name="js"}
    {load href="/static/lib/jquery/jquery.form.js"}
    {load href="/static/lib/jquery/jquery.autofill.min.js"}
    {load href="/static/lib/validator/validator.min.js"}
    {load href="/static/lib/simpleupload/simpleUpload.min.js"}
{/block}
{block name="jscode"}
<script type="text/javascript">
$(document).ready(function() {
    var settings_image = {
        uploadUrl: "{:url('@admin/upload/image')}",
        accept: "image/*",
        allowedExts: ["jpg", "jpeg", "png", "gif"], // 允许上传后缀
        allowedTypes: ["image/pjpeg", "image/jpeg", "image/png", "image/x-png", "image/gif", "image/x-gif"],
    };

    var settings_file = {
        uploadUrl: "{:url('@admin/upload/file')}",
        accept: "text/plain,application/zip,application/gzip,application/pdf",
        allowedExts: ["txt", "zip", "gzip", "pdf"],
        allowedTypes: ["text/plain", "application/zip", "application/x-zip", "application/gzip", "application/x-zip-compressed", "application/pdf"],
    };
    // 上传文件
    $("[data-param-upload]").click(function(event) {
        var param_type = $(this).data('param-type');
        var input_name = $(this).data('input-name');

        if ($("input[name=" + input_name + "]").val() != '') {
            if (param_type == 'image') {
                return sxj.msg_error('提示：请先删除图片!');
            }
            if (param_type == 'file') {
                return sxj.msg_error('提示：请先删除附件!');
            }
        }
        
        // 配置文件
        var settings = param_type == 'file' ? settings_file : settings_image;

        // 开始上传
        var startFunc = function(file) {sxj.loading();}

        // 上传成功
        var successFunc = function(response) {
            sxj.msg_success('文件上传成功');
            var data = response.data;
            $("input[name=" + input_name + "]").val(data.file_path)
        }

        // 调用上传插件
        sxj.upload(settings, successFunc, startFunc);
    });

    // 预览 下载
    $("[data-param-preview],[data-param-download]").click(function(event) {
        var input_name = $(this).data('input-name');
        var file_path = $("input[name="+input_name+"]").val();
        if(file_path == ''){
            return sxj.msg_error('提示：文件不存在');
        }
        window.open(file_path);
    });

    // 删除文件
    $("[data-param-delete]").click(function(event) {
        var input_name = $(this).data('input-name');
        var file_path = $("input[name='" + input_name + "']").val();
        if(file_path == ''){
            return sxj.msg_error('提示：文件不存在');
        }
        var url = "{:url('@admin/upload/delete')}?file_path=" + file_path;
        sxj.upload_delete(url, input_name);
    });

    // 自定义字段 自动填充
    $("form#form-page-submit").autofill({:json_encode($content)});
});
</script>
{/block}